package com.wm.task2.view;

import java.util.Scanner;

public  abstract class BaseView {
    protected Scanner sc = new Scanner(System.in);
    public void show(){
        while(true){
            printMenu();
            String choice = getChoice();
            if(choice.equals("0")){
                handleQuit();
                break;
            }
            handleChoice(choice);
            sc.nextLine();
        }
    }

    protected abstract void handleChoice(String choice);//处理选择

    protected void handleQuit() {
    }

    private String getChoice() {
        System.out.print("请输入选择：");
        String choice = sc.nextLine();
        return choice;
    }
    protected abstract String getTitle();
    protected abstract String[] getMenus();
    private void printMenu() {
        System.out.println("==="+getTitle()+"===");
        String[] menus = getMenus();
        for(int i=0;i<menus.length;i++){
            System.out.printf("%d、%s\n",i+1,menus[i]);
        }
        System.out.println("0、退出");
    }
}